package com.lcsc.verification.service.impl;

import com.lcsc.verification.dao.ComparePlanDao;
import com.lcsc.verification.model.ComparePlanModel;
import com.lcsc.verification.service.ComparePlanService;
import com.lcsc.verification.vo.ComparePlanVO;
import com.lcsc.verification.vo.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 校验计划Service
 *
 * @author liuchuan
 * @date 2018/12/5
 * @Copyright 深圳立创电子商务有限公司
 */
@Service
public class ComparePlanServiceImpl implements ComparePlanService {

    @Autowired
    private ComparePlanDao comparePlanDao;

    @Override
    public PageVO pageComparePlan(ComparePlanVO comparePlanVO) {

        Integer currentPage = comparePlanVO.getCurrentPage();
        Integer pageSize = comparePlanVO.getPageSize();

        if (currentPage == null) {

            currentPage = 1;
        }

        if (pageSize == null) {

            pageSize = 20;
        }

        // limit 手动分页
        currentPage = (currentPage - 1) * pageSize;

        comparePlanVO.setCurrentPage(currentPage);

        Long count = this.comparePlanDao.countComparePlan(comparePlanVO);

        List<ComparePlanModel> comparePlanModels = this.comparePlanDao.pageComparePlan(comparePlanVO);

        PageVO<List<ComparePlanModel>> pageVO = new PageVO<List<ComparePlanModel>>(count, comparePlanModels, currentPage, pageSize);

        return pageVO;
    }
}
